package com.system.post.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.system.post.dao.PostRepository;
import com.system.post.entity.Post;
@Service
@Transactional
public class PostService implements IPostService {
	@Autowired
	private PostRepository postRepository;
	public void saveOrUpdate(Post post) {
		
		postRepository.save(post);
	}
	public void delete(Post post) {
		
		postRepository.delete(post);
	}
	@Transactional(readOnly = true)
	public Post findOne(Long postId) {
		return postRepository.findOne(postId);
	}

	@Transactional(readOnly = true)
	public List<Post> findAll() {
		return (List<Post>) postRepository.findAll();
	}
	@Override
	public Page<Post> findAll(Specification<Post> spec, Pageable pageable) {
		return postRepository.findAll(spec, pageable);
	}
	@Override
	public void delete(List<Long> ids) {
		List<Post> posts =  (List<Post>) postRepository.findAll(ids);
		if(posts!=null) {
			postRepository.delete(posts);
		}
	}

}
